package com.flyme.module.base.provider.api;

import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.security.OpenHelper;
import com.flyme.common.core.security.OpenUserAuth;
import com.flyme.common.core.utils.ObjectUtils;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.entity.*;
import com.flyme.module.base.client.enums.CommercialEnum;
import com.flyme.module.base.client.enums.PostEnum;
import com.flyme.module.base.client.enums.ProfessionEnum;
import com.flyme.module.base.client.enums.RankEnum;
import com.flyme.module.base.provider.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 支付控制器
 */
@RestController
@RequestMapping("/third")
public class ApiThirdController {
    @Autowired
    private SysDictService sysDictService;
    @Autowired
    private SysUserEduationService sysUserEduationService;
    @Autowired
    private SysUserTrainService sysUserTrainService;
    @Autowired
    private SysUserWorkService sysUserWorkService;
    @Autowired
    private SysenumService sysenumService;
    @Autowired
    private SysExaenumService sysExaenumService;
    @Autowired
    private SysConditionitemService conditionitemService;


    /**
     * 字典项
     */
    @RequestMapping(value = "/getdicData")
    public ResultBody getdicData(String dicType) {
        List<Map<String, Object>> list = sysDictService.selectByCode(dicType);
        return ResultBody.success(list);
    }

    /**
     * 工作经历页面
     */
    @RequestMapping(value = "/work_list")
    public ResultBody work_list() {
        OpenUserAuth userAuth = OpenHelper.getUserAuth();
        EntityMap map = new EntityMap();
        List<SysUserWork> list = sysUserWorkService.selectByUserId(userAuth.getUserId());
        List<EntityMap> commercials = CommercialEnum.getList();
        List<EntityMap> posts = PostEnum.getList();
        List<SysExaenum> workingYears = sysExaenumService.findByType("workyear");
        map.put("worklist", list);
        map.put("commercials", commercials);//业态
        map.put("posts", posts);//职位
        map.put("workingYears", workingYears);//工作年限
        return ResultBody.success(map);
    }

    /**
     * 工作经历页面
     */
    @RequestMapping(value = "/addwork")
    public ResultBody addwork(SysUserWork SysUserWork) {
        OpenUserAuth userAuth = OpenHelper.getUserAuth();
        EntityMap map = new EntityMap();
        SysUserWork.setUserId(userAuth.getUserId());
        SysConditionitem item = conditionitemService.getConditionitem(2, SysUserWork.getWorkLifeleaval());
        if(ObjectUtils.isNotEmpty(item)){
            SysUserWork.setWorkValue(item.getWorkValue());
        }
        boolean a = sysUserWorkService.saveOrUpdate(SysUserWork);
        if (a) {
            return ResultBody.success();
        }
        return ResultBody.failed("提交失败");
    }

    /**
     * 初始化培训经历页面
     */
    @RequestMapping(value = "/train_list")
    public ResultBody train_list() {
        OpenUserAuth userAuth = OpenHelper.getUserAuth();
        EntityMap map = new EntityMap();
        List<SysUserTrain> list = sysUserTrainService.selectByUserId(userAuth.getUserId());
        map.put("trainlist", list);
        return ResultBody.success(map);
    }



    /**
     * 培训经历提交
     */
    @RequestMapping(value = "/addtrain")
    public ResultBody addTrain(SysUserTrain sysUserTrain) {
        OpenUserAuth userAuth = OpenHelper.getUserAuth();
        EntityMap map = new EntityMap();
        sysUserTrain.setUserId(userAuth.getUserId());
        boolean a=sysUserTrainService.saveOrUpdate(sysUserTrain);
        if (a){
            return ResultBody.success(sysUserTrain);
        }
        return ResultBody.failed("提交失败");
    }

    @RequestMapping(value = "/educationlist")
    public ResultBody educationlist(SysUserEduation SysUserEduation) {
        OpenUserAuth userAuth = OpenHelper.getUserAuth();
        SysUserEduation.setUserId(userAuth.getUserId());
        EntityMap entityMap=new  EntityMap();
        List<SysUserEduation> eduationList=sysUserEduationService.selectByUserId(userAuth.getUserId());
        entityMap.put("eduationList",eduationList);

//        List<EntityMap> educationList = EducationEnum.getList();
        List<SysExaenum> educationList = sysExaenumService.findByType("xueli");
        List<EntityMap> professionList = ProfessionEnum.getList();
        List<EntityMap> rankList = RankEnum.getList();
        entityMap.put("educationList", educationList);//学历分类
        entityMap.put("professionList", professionList);//专业分类
        entityMap.put("rankList", rankList);//级别分类
        return ResultBody.success(entityMap);
    }
    /**
     * 提交教育经历
     */
    @RequestMapping(value = "/addEducation")
    public ResultBody addEducation(SysUserEduation SysUserEduation) {
        OpenUserAuth userAuth = OpenHelper.getUserAuth();
        SysUserEduation.setUserId(userAuth.getUserId());
        boolean a=sysUserEduationService.saveOrUpdate(SysUserEduation);
        if (a){
            return ResultBody.success(SysUserEduation);
        }
        return ResultBody.failed("提交失败");
    }

}











